# -*- coding: UTF-8 -*-

import base
import xml.etree.ElementTree as et

class Imageshack(base.Core):
    
    __label__ = "Imageshack.us"
    __url__ = "www.imageshack.us"
    
    def uploadFile(self, image):
        params = {"fileupload": open(image, "rb"), "xml":'yes'}
        f = self.opener.open("http://www.imageshack.us/index.php", params)
        data = f.read()
        f.close()
        return data
        
    def response(self, data):
        if data == 'failed':
            return "XML return failed"
        xml = et.XML(data)
        self.image_link = xml.find("image_link").text
        self.thumb_link = xml.find("thumb_link").text
        self.ad_link = xml.find("ad_link").text
        self.image_name = xml.find("image_name").text
        return True
